home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK1.toast / Development Kits (Disc 1) / QuickDraw 3D / Development / 3DMF parser / 0.9 version / MFGROUPS.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-21  |  3.1 KB  |  132 lines  |  [TEXT/MPS ]

  1. /*==============================================================================
  2.  *
  3.  *    File:        MFGROUPS.C
  4.  *
  5.  *    Function:    Handle group state and attribute states.
  6.  *
  7.  *    Author(s):    Rick Wong (RWW), Duet Development Corp.
  8.  *
  9.  *    Copyright:    (c) 1995 by Apple Computer, Inc., all rights reserved.
  10.  *
  11.  *    Change History (most recent first):
  12.  *        Fabio    Changed file name to 8 characters
  13.  *        F2R_RWW Use the simple object model, eliminating the need for most
  14.  *                of the meat of all these routines.
  15.  *        F2N_RWW    File created.
  16.  *==============================================================================
  17.  */
  18.  
  19. #include "MFGROUPS.H"
  20.  
  21. #include "MFERRORS.H"
  22. #include "MFSUBOBJ.H"
  23. #include "MFASSERT.H"
  24. #include "MFINTOBJ.H"
  25. #include "MFMACROS.H"
  26. #include "MFMEMORY.H"
  27.  
  28. /*==============================================================================
  29.  *    MF3D_InitGroup
  30.  *
  31.  *    Setup internal file record group stuff
  32.  *==============================================================================
  33.  */
  34. MF3DErr
  35. MF3D_InitGroup(
  36.     MF3D_FilePtr    ioMetafile)
  37. {
  38.     MF3DErr    result;
  39.  
  40.     MFASSERT(ioMetafile->readWrite == MF3D_MetafileRead);
  41.  
  42.     result = kMF3DNoErr;
  43.  
  44.     ioMetafile->groupState.traversalFlags = MF3DDisplayGroupDefaultFlags;
  45.     ioMetafile->groupState.parent = NULL;
  46.  
  47.     return result;
  48. }
  49.  
  50. /*==============================================================================
  51.  *    MF3D_PushGroup
  52.  *
  53.  *    Make a copy of the current group and push it onto the group stack
  54.  *==============================================================================
  55.  */
  56. MF3DErr
  57. MF3D_PushGroup(
  58.     MF3D_FilePtr    ioMetafile)
  59. {
  60.     MF3D_GroupStatePtr    oldGroup;
  61.     MF3DErr                result;
  62.  
  63.     MFASSERT(ioMetafile->readWrite == MF3D_MetafileRead);
  64.  
  65.     result = kMF3DNoErr;
  66.  
  67.     MF3D_Allocate(oldGroup);
  68.  
  69.     if (result == kMF3DNoErr)
  70.     {    oldGroup->traversalFlags =
  71.                 ioMetafile->groupState.traversalFlags;
  72.         oldGroup->parent = ioMetafile->groupState.parent;
  73.         ioMetafile->groupState.parent = oldGroup;
  74.     }
  75.  
  76.     return result;
  77. }
  78.  
  79. /*==============================================================================
  80.  *    MF3D_PopGroup
  81.  *
  82.  *    Pop the group stack
  83.  *==============================================================================
  84.  */
  85. MF3DErr
  86. MF3D_PopGroup(
  87.     MF3D_FilePtr    ioMetafile)
  88. {
  89.     MF3D_GroupStatePtr    parentGroup;
  90.     MF3DErr                result;
  91.  
  92.     MFASSERT(ioMetafile->readWrite == MF3D_MetafileRead);
  93.  
  94.     result = kMF3DNoErr;
  95.  
  96.     parentGroup = ioMetafile->groupState.parent;
  97.     if (ioMetafile->groupState.parent == NULL)
  98.         result = kMF3DErrTooManyEndGroups;
  99.  
  100.     if (result == kMF3DNoErr)
  101.     {    ioMetafile->groupState.parent = parentGroup->parent;
  102.         MF3D_Free(parentGroup);
  103.     }
  104.  
  105.     return result;
  106. }
  107.  
  108. /*==============================================================================
  109.  *    MF3D_DisposeGroup
  110.  *
  111.  *    Clean up top-level group pointers
  112.  *==============================================================================
  113.  */
  114. MF3DErr
  115. MF3D_DisposeGroup(
  116.     MF3D_FilePtr    ioMetafile)
  117. {
  118.     MF3DErr    result;
  119.  
  120.     MFASSERT(ioMetafile->readWrite == MF3D_MetafileRead);
  121.  
  122.     result = kMF3DNoErr;
  123.  
  124.     if (ioMetafile->groupState.parent != NULL)
  125.     {    result = kMF3DErrNotEnoughEndGroups;
  126.         MF3D_PopGroup(ioMetafile);            /* errors ignored */
  127.         MF3D_DisposeGroup(ioMetafile);        /* because we already have one */
  128.     }
  129.  
  130.     return result;
  131. }
  132.